<template>
  <div>
    <!-- 查看详情弹框 -->
    <el-dialog
      title="详情"
      :visible.sync="eventChildShow"
      width="60%"
      :before-close="handleCloses"
      append-to-body
      :close-on-click-modal="false"
    >
      <div class="sousuojg6_10">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="产品SN">
            <el-input
              v-model="formInline.productNo"
              placeholder="请输入产品SN"
            ></el-input>
          </el-form-item>
          <el-form-item style="float: right;height: 0px;margin-top: 0px">
            <el-button
              type="primary"
              @click="queryProductInfo"
              icon="el-icon-search"
              class="btn"
              >搜索</el-button
            >
          </el-form-item>
        </el-form>
      </div>

      <p class="shopList"></p>

      <el-table
        v-loading="listLoading"
        :data="tableData"
        border
        height="480"
        :header-cell-style="{ background: '#DCDCDC', color: '#222' }"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          align="center"
          min-width="40"
        ></el-table-column>
        <el-table-column
          prop="productNo"
          align="center"
          min-width="200"
          label="产品SN"
        ></el-table-column>
        <el-table-column align="center" min-width="200" label="开通状态">
          <template slot-scope="scope">
            <span v-if="scope.row.openStatus == 0">未开通</span>
            <span v-if="+scope.row.openStatus > 0">已开通</span>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="200" label="达标状态">
          <template slot-scope="scope">
            <span v-if="scope.row.amtStatus == 0">未达标</span>
            <span v-if="+scope.row.amtStatus > 0">已达标</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="awardAmount"
          align="center"
          min-width="200"
          label="奖励金额"
        ></el-table-column>
      </el-table>
      <el-button type="primary" @click="productInfoExport" class="btnExport"
        >批量导出</el-button
      >
      <el-pagination
        background
        style="text-align: right;"
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="formInline.page"
        :page-size="formInline.number"
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[10, 20, 30, 40, 50]"
        :total="totalNum"
      ></el-pagination>
    </el-dialog>
  </div>
</template>
<script>
import bus from "../../assets/js/bus";
import https from "../../plugins/https.js";
import qs from "qs";
export default {
  props: {
    eventChildShow: {
      type: Boolean,
      default() {
        return false;
      }
    },
    detailsData: {
      type: Object
    }
  },
  data() {
    return {
      formInline: {
        officeUid: "",
        activeUid: "",
        productNo: "",
        oemUid: localStorage.getItem("uid"),
        page: 1,
        number: 10
      },
      totalNum: 0, //总页数
      tableData: [],
      listLoading: false
    };
  },
  watch: {
    eventChildShow(n) {
      if (n === true) {
        this.queryProductInfo();
      }
    }
  },
  mounted() {
    // console.log(555, this.eventShow)
  },
  methods: {
    queryProductInfo() {
      console.log(33, this.detailsData);
      this.formInline.officeUid = this.detailsData.officeUid;
      this.formInline.activeUid = this.detailsData.activeUid;
      this.listLoading = true;
      https.queryProductInfo(this.formInline).then(res => {
        if (res.data.code !== "0000") {
          this.$notify({ title: "错误", message: res.data.msg, type: "error" });
          this.listLoading = false;
          return;
        }
        console.log(666, res);
        this.tableData = res.data.data;
        this.totalNum = res.data.total;
        this.listLoading = false;
      });
    },
    handleCloses(done) {
      bus.$emit("eventChildsuccess", false);
    },
    productInfoExport() {
      // window.location.href = this.GLOBAL.httpurl + `/api/active/productInfo/excel/export?${qs.stringify(this.formInline)}`;
      var _this = this;
      _this
        .axios({
          //axios请求
          method: "post",
          url: "/api/active/productInfo/excel/export",
          responseType: "blob",
          data: _this.formInline
        })
        .then(function(d) {
          let blob = new Blob([d.data], { type: "application/vnd.ms-excel" });
          /*let objectUrl = URL.createObjectURL(blob);
                        window.location.href = objectUrl;*/

          var date = new Date();

          var year = date.getFullYear();

          var month = date.getMonth() + 1;
          var day = date.getDate();
          var hour = date.getHours();
          var minute = date.getMinutes();
          var second = date.getSeconds();
          date =
            year +
            "" +
            month +
            "" +
            day +
            "" +
            hour +
            "" +
            minute +
            "" +
            second; //'+date+'

          var downloadElement = document.createElement("a");
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.href = href;
          downloadElement.download = "权益列表" + date + ".xls"; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        })
        .catch(function(error) {
          //axios请求失败回调
          console.log(error);
        });
    },
    handleSizeChange(val) {
      this.formInline.number = val; //动态改变
    },
    handleCurrentChange(val) {
      this.formInline.page = val; //动态改变
    }
  }
};
</script>
<style scoped>
.btnExport {
  float: left;
  margin-top: 10px;
  margin-bottom: 10px;
}
.pagination {
  margin-top: 10px;
}
.sousuojg6_10 {
  /* float: left; */
  font-size: 16px;
  color: #222;
  padding-bottom: 0;
  box-sizing: border-box;
  background-color: #f6f6f6;
  border-radius: 5px;
}
.shopList {
  width: 100%;
  border-bottom: 1px solid #ccc;
  line-height: 50px;
  font-size: 16px;
  height: 30px;
  margin-bottom: 30px;
}
</style>
